1 /***
2 * Copyright 2003, 2004, 2005. CodeStreet LLC.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15 package com.codestreet.selector.parser;
16
17 import java.util.Map;
18
19 /***
20 * Class to represent the <tt>String</tt> equality operator. Immutable.
21 *
22 * @author Jawaid Hakim.
23 */
24 class OpStringEQ implements IExpressionString
25 {
26 /***
27 * Ctor.
28 *
29 * @param lhs
30 * LHS.
31 * @param rhs
32 * RHS.
33 */
34 public OpStringEQ(final IExpression lhs, final IExpression rhs)
35 {
36 lhs_ = lhs;
37 rhs_ = rhs;
38 }
39
40 public Object eval(final Map identifiers)
41 {
42 Object oLhs = lhs_.eval(identifiers);
43 Object oRhs = rhs_.eval(identifiers);
44
45 return eval(oLhs, oRhs);
46 }
47
48 public Object eval(final IValueProvider provider, final Object corr)
49 {
50 Object oLhs = lhs_.eval(provider, corr);
51 Object oRhs = rhs_.eval(provider, corr);
52
53 return eval(oLhs, oRhs);
54 }
55
56 private Object eval(final Object oLhs, final Object oRhs)
57 {
58 if (!(oLhs instanceof String))
59 return Result.RESULT_UNKNOWN;
60
61 if (!(oRhs instanceof String))
62 return Result.RESULT_UNKNOWN;
63
64 return (oLhs.equals(oRhs)) ? Result.RESULT_TRUE : Result.RESULT_FALSE;
65 }
66
67 private final IExpression lhs_;
68
69 private final IExpression rhs_;
70
71 }
This page was automatically generated by Maven